/* panel.hh
* This file is part of ncursesxx library
* Copyright (c) 2003,2004 by Stanislav Ievlev
*
* This file is covered by the GNU Library General Public License,
* which should be included with libncursesxx as the file COPYING.
*/
#ifndef NCURSESXX_PANEL_HH__
#define NCURSESXX_PANEL_HH__

#include <vector>

#include <panel.h>

#include <ncurses/window.hh>

namespace ncurses
{
	/**
	 * meaning of coordinates
	 */
	enum coords_type
	{
		absolute,     /**< absolute coordinate of screen */
		relative /**< relative to previous position coordinate */
	};

	/**
	 * Enchancement of Window,
	 * Panel supports depth and overlapping feature
	 */
	class panel: public window
	{
		typedef std::vector<panel*> child_vector; /**< list of the panels */
	public:
		panel(panel *parent = 0);
		virtual ~panel();

		virtual void top(); /**< put this panel on top of all panels in the  stack */
		virtual void bottom(); /**< put this panel at the bottom of all panels */
		virtual void show(); /**<  makes  a hidden panel visible by placing it on top of the panels */
		virtual void hide(); /**< removes  the  given panel from the panel stack and thus hides it from view */

		bool	hidden() const; /**< are this widget hidden? */
		bool    higher(const panel&) const; /**< are we higher other panel */


		virtual void draw(); /**< draw widget specific content over general panel */

		void prepare(); /**< draw this widget and all subwidgets */
		void visualize(); /**< equivalent of prepare + show */

		/**
		 * move panel to the other place, refresh state of other panels
		 * @param x absolute or relative to previous position x coordinate
		 * @param y absolute or relative to previous position y coordinate
		 * @param 
		 */
		virtual void move(int x, int y, coords_type type = relative);
	protected:
		void	add_child(panel *p); /**< helper to create panel's hieracly */
		void	del_child(panel *p); /**< delete from the childs list */
	private:
		//hide dangerous operations
		panel(const panel& other);
		panel& operator=(const panel& other);
		
		PANEL *panel_; /**< internal ncurses panel structure */
		panel *parent_; /**< parent panel, if we have*/
		child_vector childs_; /**< childs of this */
	};

	class move_to /**< helper functor to move vector of panels */
	{
	public:
		move_to(int x, int y): x_(x), y_(y) {}
		void operator()(panel *p) { p->move(x_, y_); }
	private:
		int x_;
		int y_;
	};

	inline
	bool operator>(const panel& lhs,const panel& rhs)
	{
	    return lhs.higher(rhs);
	}

	inline
	bool operator<(const panel& lhs,const panel& rhs)
	{
	    return rhs.higher(lhs);
	}
	
}

#endif
